import {reactive, ref} from "vue"
import {defineStore} from "pinia"
import {UploadUserFile} from "element-plus";

export const usePublicCompStore = defineStore("publicCom", () => {
  // tag列表
  const tags = ref([])
  // 上传文件的容器(如果增加字段的话，需要同步增加files/index.vue中的beforeHideMethod方法中的值)
  const container = reactive({
    file: {
      name: '',
      percentage: 0,
      status: 'ready',
      size: 0,
      url: undefined,
      raw: undefined,
      uid: 0
    },
    hash: '',
    key: '',
    s3UploadID: '',
    status: '',        // hash、uploading、uploaded
    worker: null,
  })
  // 上传的文件列表
  const fileList = ref<string[]>([])
  // 上传的进度
  const fakeUploadPercentage = ref(0)
  // 计算hash的速度
  const hashPercentage = ref(0)
  // 定义一个 ref 来跟踪上传是否被中断
  const isUploadInterrupted = ref(false);
  return {tags, container, fileList, fakeUploadPercentage, hashPercentage, isUploadInterrupted}
})
